import { createApp } from 'vue';
// 1. 导入[js/ts]文件
import './assets/iconfont/index.js';
import './style.css';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import App from './App.vue';
import router from './router';
import mobile from './router/mobile.js';

import SvgIcon from './components/SvgIcon/index.vue';
import Empty from './components/Empty/index.vue';

import isPc from './util/isPc.js';
import { refreshRem } from './util/rem.js';

const app = createApp(App);
// 2. 注册SvgIcon
app.component('svg-icon', SvgIcon);

// 此处判断是否为pc，如果是pc则引用element-ui
console.log(isPc());
if (isPc()) {
  app.use(ElementPlus, {
    locale: zhCn,
  });
  app.use(router);
} else {
  refreshRem();
  app.use(mobile);
  app.component('my-empty', Empty);

  let tid;
  window.addEventListener(
    'resize',
    function () {
      clearTimeout(tid);
      tid = setTimeout(refreshRem, 300);
    },
    false
  );
  window.addEventListener(
    'pageshow',
    function (e) {
      if (e.persisted) {
        // 页面从浏览器的缓存中读取
        clearTimeout(tid);
        tid = setTimeout(refreshRem, 300);
      }
    },
    false
  );
}

app.mount('#app');
